﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using Microsoft.WindowsAzure;

namespace DevStorageSync
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                string[] assemblies;

                // Parse command line arguments
                assemblies = ParseArgs(args);

                // Set configuration publisher to always use development storage
                CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                {
                    // Provide the configSetter with the initial value
                    configSetter("UseDevelopmentStorage=true");
                });

                Application.Run(new SyncForm(assemblies));
            }
            catch (Exception e)
            {
                MessageBox.Show("An error has occurred: " + e.Message);
            }
        }

        /// <summary>
        /// Parses the command line arguments and returns an array of assemblies.
        /// </summary>
         private static string[] ParseArgs(string[] args)
        {
            // Get assemblies
            if (args.Length == 0)
            {
                throw new Exception("No assemblies set in command line arguments.");
            }

            return args[0].Replace("\"", "").Split(";".ToCharArray());
        }
    }
}